package com.lagou.模块四;

public class Worker {
    private int age;
    private String name;

    public Worker() {
    }

    public Worker(int age, String name) {

        setAge(age);
        setName(name);
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age < 18 || age >150){
            try {
                throw new AgeException("年龄不合理");
            } catch (AgeException e) {
                e.printStackTrace();
            }
        }else{
            this.age = age;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (null == name){
            try {
                throw new NameException("名字不合理");
            } catch (NameException e) {
                e.printStackTrace();
            }
        }else{
            this.name = name;
        }
    }
}
